package com.example.a0413demo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
        ListView mListview;
        FrameLayout mFrame;
        List<User>mList =new ArrayList();
        List<Fragment> fragmentList=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }
    private void initData(){
        listViewData();
        addFragment();

    }

    private void addFragment() {
     FragmentTransaction transaction= getSupportFragmentManager().beginTransaction();
     ShowFragment showFragment=new ShowFragment();
     for(int i=0;i<mList.size();i++){
         Fragment fragment = showFragment.getShowFragment(mList.get(i).getName());
         fragmentList.add(fragment);
     }
      showFragment.getShowFragment("页面1");
    }

    private void listViewData() {
        for (int i=0;i<10;i++){
            mList.add(new User("页面"+i));
        }
        MyAdapter adapter=new MyAdapter(mList,this);
        mListview.setAdapter(adapter);
    }

    private void initView(){
        mListview=findViewById(R.id.mListview);
        mFrame=findViewById(R.id.mFrame);
    }
}